#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>

#define NUM 128

int main()
{
  char command[NUM];
  while(1)
  {
    // 1.
    char* argv[64] = {NULL};
    command[0] = '\0';
    printf("[sherry@myhostname myfile]# ");
    fflush(stdout);
    // 2.
    fgets(command, NUM, stdin);
    command[strlen(command) - 1] = '\0';
    // 3.
    const char* sep = " ";
    argv[0] = strtok(command, sep);
    int i = 1;
    while(argv[i] = strtok(NULL, sep))
    {
      i++;
    }
    //for(int j = 0; argv[j]; j++)
    //  printf("argv[%d] = %s\n", j, argv[j]);

    if(fork() == 0)
    {
      execvp(argv[0], argv);
      exit(1);
    }
    waitpid(-1, NULL, 0);
  }
  return 0;
}
